import logistCompanyRoutes from '@/views/busipart/logistcompany/index'
import type { App } from 'vue'
import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHistory } from 'vue-router'
import remainingRouter from './modules/remaining'
import { Layout } from '@/utils/routerHelper'



// 创建包含新路由的数组
const customRoutes: RouteRecordRaw[] = [
  ...(remainingRouter as RouteRecordRaw[]), // 强制类型断言
  ...(logistCompanyRoutes as RouteRecordRaw[]),
  
  {
    path: '/customer_manager/cust-follow',
    name: 'CustFollow',
    component: () => import('@/views/customermanager/custfollow/index.vue'),
    meta: { title: '客户跟进记录' }
  },
  {
    path: '/customer_manager/cust-info-detail',
    name: 'CustInfoDetail',
    component: () => import('@/views/customermanager/custfollow/components/CustInfoDetail.vue'),
    meta: { title: '客户基本信息' }
  },

  {
    path: '/busipart/supplierinfo/detail',
    name: 'SupplierInfoDetail',
    component: () => import('@/views/busipart/components/base.vue'),
    meta: {
      title: '供应商详情'
    }
  },
  // 添加企业注册和岗位管理路由
  {
    path: '/business',
    component: Layout,
    name: 'Business',
    meta: { 
      title: '企业管理',
      icon: 'ep:office-building'
    },
    children: [
      {
        path: 'company',
        name: 'BusinessCompany',
        component: () => import('@/views/business/company/index.vue'),
        meta: { 
          title: '企业注册',
          icon: 'ep:office-building'
        }
      },
      {
        path: 'jobpost',
        name: 'BusinessJobpost',
        component: () => import('@/views/business/jobpost/index.vue'),
        meta: { 
          title: '岗位管理',
          icon: 'ep:briefcase'
        }
      }
    ]
  }
  // 可以在这里继续添加其他路由...
]
console.log('注册的路由：', customRoutes)

// 创建路由实例
const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_BASE_PATH),
  strict: true,
  routes: customRoutes, // 使用新的路由数组
  scrollBehavior() {
    return { left: 0, top: 0 }
  }
})

export const resetRouter = (): void => {
  const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root']
  router.getRoutes().forEach((route) => {
    const { name } = route
    if (name && !resetWhiteNameList.includes(name as string)) {
      router.hasRoute(name) && router.removeRoute(name)
    }
  })
}

export const setupRouter = (app: App<Element>) => {
  app.use(router)
}

export default router